#include "label.h"

#include "hardware/lcd_init.h"
#include "hardware/lcd.h"
#include "mid/printf.h"
#include "app/text.h"
#include "mid/utils.h"

#include <string.h>

Label BuildLabel(int x, int y, const char *txt, uint16_t fgColor, uint16_t bgColor)
{
    Label label;

    label.x = x;
    label.y = y;
    label.text = txt;
    label.fgColor = fgColor;
    label.bgColor = bgColor;
    label.maxW = 0;
    label.maxH = 0;
    return label;
}

void DrawLabel(Label *label)
{
    int strW = StrWidth(label->text);

    if (strW >= label->maxW)
        label->maxW = strW + 1;
    if (FONT_SIZE >= label->maxH)
        label->maxH = FONT_SIZE + 1;

    //绘制背景矩形
    LCD_Fill(label->x - label->maxW / 2, label->y - label->maxH / 2, label->x + label->maxW / 2, label->y + label->maxH / 2, label->bgColor);
    LCD_ShowStringV2(label->x - strW / 2, label->y - FONT_SIZE / 2, label->text, label->fgColor, label->bgColor, FONT_SIZE, 1);
}